package com.example.consult.mapper;

import com.example.consult.model.ConsultLog;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface RecordMapper {

    @Insert("insert into consult_log(log_id,start_time,user_account,employee_account)" +
            "value(#{log_id},#{start_time},#{user_account},#{employee_account})")
    public int insert(ConsultLog log);

    @Update("update consult_log(deal_time,detail,satisfy,is_solved)" +
            "value(#{deal_time},#{detail},#{satisfy},#{is_solved}) where log_id=#{log_id}")
    public int update(ConsultLog log);

    @Select("select * from consult_log where user_account=#{userAccount}")
    public List<ConsultLog> searchByUserAccount(String userAccount);

    @Select("select * from consult_log where employee_account=#{employeeAccount}")
    public List<ConsultLog> searchByEmployeeAccount(String employeeAccount);

    /*
    查询已解决
     */
    @Select("select * from consult_log where state=${1}")
    public List<ConsultLog> searchBySolved();

    /*
    查询未解决
     */
    @Select("select * from consult_log where state=${0}")
    public List<ConsultLog> searchByNotSolved();

    /*
    满意度降序
     */
    @Select("select * from consult_log order by satisfy DESC")
    public List<ConsultLog> searchBySatisfyDesc();

    /*
    满意度升序
     */
    @Select("select * from consult_log order by satisfy DESC")
    public List<ConsultLog> searchBySatisfyIncr();

    @Select("select count(*) from consult_log where employee_account=#{employeeAccount}")
    public int getConsultTimeByEmployee(String employeeAccount);

}
